<?php
declare (strict_types=1);

namespace app\api\controller\v4;

use app\common\models\Question;

class WordExam extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'neirong' => $this->group(),   //获取单词认读测试
        ]);
    }

    /**
     * 获取单词认读测试
     *
     * @return \think\Response
     */
    public function group()
    {
        //列表
        $model = new Question();
//        $page = input('page/d', 1);
//        $pageSize = input('pageSize/d', 1);
        $paper_id = input('id/d');
        $data = $model->where(['status' => 1, 'paper_id' => $paper_id])
            ->field('id,paper_id,title,desc,content,answer')
            ->order('id', 'asc')
//            ->page($page, $pageSize)
            ->select();
        foreach ($data as &$value) {
            $value['paper_id'] = $value->paper->title;
            $value['content'] = json_decode($value['content']);
            unset($value->paper);
        }
//        $rows = count($model->where('grade_id')->select()->toArray());
//        $maxPage = ceil($rows / $pageSize);
        return ['data' => $data, 'total' => count($data)];
    }
}
